package com.zhen.aikan.controller;

import com.zhen.aikan.service.IUtilService;
import com.zhen.aikan.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author LiJiaZhen
 * @date 2023/9/19 23:03
 */
@RestController
@RequestMapping("/api/code")
public class VerificationCodeController {
    @Autowired
    private IUtilService utilService;
    @ApiOperation("获取验证码")
    @PostMapping("/getCode")
    public Result getVerificationCode(@RequestBody Map<String,String> params){
        utilService.getVerificationCode(params.get("email"));
        return Result.ok();
    }

    @ApiOperation("验证验证码是否正确")
    @PostMapping("/verifyCode")
    public Result verifyCode(@RequestBody Map<String,String> params){
        boolean isOk = utilService.verifyCode(params.get("email"),params.get("code"));
        return Result.ok(isOk?1:0);
    }
}
